package com.example.contrl;

import com.example.pojo.Course;
import com.example.pojo.Result;
import com.example.service.CourseService;
import com.example.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Vector;

@Slf4j
@RestController
public class CourseContrl {
    @Autowired
     private CourseService courseService;


    /*
     * 查询课程
     * */
    @PostMapping("/course")
    public Result course(){
        log.info("查询课程");
        Vector<Course> courses=courseService.select();
        return Result.success(courses);
    }

    /*
     * 条件查询课程
     * */
    @GetMapping("/selectCourse")
    public Result  selectTeacher( String name, String state,String teacher){
        log.info("查询课程{}，{},{}",name,state,teacher);
        Vector<Course> courses=courseService.selectCourse(name,state,teacher);
        return Result.success(courses);
    }

    /*
     * 修改课程
     * */
    @PostMapping("/course/update")
    public Result updateStudent(@RequestBody Course course){
        log.info("修改{}",course);
        courseService.update(course);
        return Result.success();
    }

    /*
     * 删除课程
     * */
    @GetMapping("/course/delete/{id}")
    public Result deleteCourse(@PathVariable String id){
        log.info("删除课程{}",id);
        courseService.delete(id);
        return Result.success();
    }

    /*
    * 添加课程
    * */
    @PostMapping("/course/add")
    public Result addCourse(@RequestBody Course course){
        log.info("添加课程{}",course);
        courseService.add(course);
        return Result.success();
    }

    /*
    * 课程表
    *
    * */
    @GetMapping("/StudentCourse/{id}")
    public Result StudentCourse(@PathVariable String id){
        log.info("{}学生课程表",id);
        Vector<Course>   courses = courseService.studentCourse(id);
        return Result.success(courses);
    }
}
